<template>
  <div class="app-container">
    <div class="contentDiv">
   <el-form ref="form" :model="form" label-width="100px">
    <el-row>
      <el-col :span="12">
        <el-row>
        <el-col :span=12 >
          <el-form-item label="协会Logo" prop="codeUrl">
          <el-upload
          class="avatar-uploader"
          ref="upload"
          :action="upload.url"
          :headers="upload.headers"
          :show-file-list="false"
          :on-success="handleCodeSuccess"
          >
          <img v-if="logoUrl" :src="logoUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
          </el-form-item>
        </el-col>
         <el-col :span=12 >
          <el-form-item label="公众号二维码">
          <el-upload
          class="avatar-uploader"
          ref="upload"
          :action="upload.url"
          :headers="upload.headers"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          >
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
          </el-form-item>
        </el-col>
        </el-row>
        <el-form-item label="H5端主题色">
          <el-color-picker v-model="form.color" @change="changeColor"></el-color-picker>
        </el-form-item>
         <el-form-item label="微信分享描述文本" prop="asDesc">
          <el-input type="textarea" v-model="form.asDesc"></el-input>
      </el-form-item>
      <el-form-item label="H5首页标题" prop="pageTitle">
          <el-input  v-model="form.pageTitle"></el-input>
      </el-form-item>
        <el-form-item label="会员认证按钮" prop="memberName">
      <el-input  v-model="form.memberName"></el-input>
      </el-form-item>
      <el-form-item label="入会申请按钮" prop="applyTip">
      <el-input  v-model="form.applyTip"></el-input>
      </el-form-item>
      <el-form-item label="个人入会申请提示" prop="applyPersonTip">
      <el-input  v-model="form.applyPersonTip"></el-input>
      </el-form-item>
      <el-form-item label="企业入会申请提示" prop="applyCompanyTip">
      <el-input  v-model="form.applyCompanyTip"></el-input>
      </el-form-item>
      <el-form-item label="团体入会申请提示" prop="applyGroupTip">
      <el-input  v-model="form.applyGroupTip"></el-input>
      </el-form-item>
      <el-form-item label="值班领导模块提示" prop="leaderName">
      <el-input  v-model="form.leaderName"></el-input>
      </el-form-item>
      <el-form-item label="值班人员模块提示" prop="personnelName">
      <el-input  v-model="form.personnelName"></el-input>
      </el-form-item>
      <el-form-item label="客服地址" prop="customerUrl">
      <el-input  v-model="form.customerUrl"></el-input>
      </el-form-item>
      <el-form-item label="商城地址" prop="shopLink">
      <el-input  v-model="form.shopLink"></el-input>
      </el-form-item>
      <el-form-item label="首页tag栏" prop="pageTitle"> 
      <el-button type="primary" round icon="el-icon-setting" size="mini" @click="addTag(form)">设置tag栏</el-button>
      </el-form-item>
      <el-form-item label="线上办公管理" prop="pageTitle">
       <el-button type="primary" round icon="el-icon-setting" size="mini" @click="addTitle(form)">设置办公模块</el-button>
      </el-form-item>
      <el-form-item label="启用-首页海报" prop="pageTitle">
      <el-switch
        v-model="form.posterSwitch"
        :active-value="1"
        :inactive-value="0"
        active-color="#13ce66"
        inactive-color="#ff4949">
      </el-switch>
      </el-form-item>
      <el-form-item label="开启-通讯录" prop="pageTitle">
      <el-switch
          v-model="form.posterSwitch"
          :active-value="1"
          :inactive-value="0"
          active-color="#13ce66"
          inactive-color="#ff4949">
        </el-switch>
      </el-form-item>
      </el-col>
      <el-col :span="12" :xs="12">
         <el-form-item label="" prop="asTitle">
           <div class="divList">
            <el-scrollbar class="scrollbar_wrap">
         <editor v-model="form.asTitle" :min-height="750"/>
            </el-scrollbar>
           </div>
         </el-form-item>
      </el-col>
      </el-row>
    </el-form>
  </div>
   <div class="contentDiv"> <el-button type="primary" @click="submitForm">保 存</el-button></div>
  <el-dialog :title="title" :visible.sync="tagOpen" width="70%" append-to-body>
   <Navigation :naData="this.form.asId"/>
  </el-dialog> 
  <el-dialog :title="title" :visible.sync="titleOpen" width="70%" append-to-body>
   <Submodule :naData="this.form"/>
  </el-dialog> 
  </div>

</template>

<script>
import { listWxconfig, getWxconfig, delWxconfig, addWxconfig, updateWxconfig } from "@/api/allocation/wxconfig";
import { getToken } from "@/utils/auth";
import Navigation from '../navigation'
import Submodule from '../submodule'
export default {
  name: "Wxconfig",
  components: {
    Navigation,
    Submodule
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //协会二维码
      imageUrl:'',
      //协会图标
      logoUrl:'',
      //tag列表
      gridData:[],
      // 微信小程序配置表格数据
      wxconfigList: [],
      labelPosition:'left',
      // 弹出层标题
      title: "",
      color1:'#409EFF',
      // 是否显示弹出层
      open: false,
      //是否显示tag栏弹出层
      tagOpen:false,
      //是否显示线上办公弹出层
      titleOpen:false,
      value:'',
      upload:{
         // 设置上传的请求头部
      headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
      url: process.env.VUE_APP_BASE_API + "/content/press/importData"
    },
      // 查询参数
      queryParams: {
        asId: null,
      },
      //tag栏查询参数
      tagQueryParams: {
         pageNum: 1,
        pageSize: 10,
        asId: null,
      },   
    
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wechatType: [
          { required: true, message: "公众号类型：1服务号，2订阅号不能为空", trigger: "change" }
        ],
        asId: [
          { required: true, message: "协会id不能为空", trigger: "blur" }
        ],
        officeName: [
          { required: true, message: "移动办公名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    createIndex(index){
      return (this.tagQueryParams.pageNum-1) *(this.tagQueryParams.pageSize)+index+1;
    },
    /** 查询微信小程序配置*/
    getList() {
      this.loading = true;
      listWxconfig(this.queryParams).then(res => {
        console.info(res);
        this.form = res.data;
        this.logoUrl=res.data.iconUrl;
        this.imageUrl=res.data.codeUrl;
        if(res.data.color==null){

        }
        this.loading = false;
      });
    },
    //设置tag栏
    addTag(data){
      this.form.asId=data.asId;
      this.tagOpen=true;
      this.title="导航栏数据"
    },
    //设置线上办公
    addTitle(data){
      this.form=data;
      this.titleOpen=true;
      this.title="移动办公"
    },
    //
    //更改H5主题颜色
    changeColor(data){
      console.info(data);
      this.form.color=data;
    },
    // 协会logo
    handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
        if(res.codeUrl==200){
          this.form.iconUrl=res.data;
        }else{
          this.$modal.confirm("协会logo上传失败");
        }
      },
    //协会二维码
    handleCodeSuccess(res,file){
    this.logoUrl = URL.createObjectURL(file.raw);
    if(res.code==200){
      this.form.codeUrl=res.data;
    }else{
      this.$modal.confirm("协会二维码上传失败");
    }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        wechatType: null,
        asId: null,
        appId: null,
        appSecret: null,
        color: null,
        codeUrl: null,
        iconUrl: null,
        pageTitle: null,
        asTitle: null,
        asDesc: null,
        duesRemark: null,
        officeName: null,
        contactsStatus: 0,
        personalStatus: 0,
        groupStatus: 0,
        companyStatus: 0,
        fileUrlOne: null,
        fileUrlTwo: null,
        fileUrlThree: null,
        memberName: null,
        memberRemark: null,
        companyRemark: null,
        groupRemark: null,
        posterSwitch: null,
        storeSwitch: null,
        shopLink: null,
        contactsVisible: null,
        contactsVisibleJoin: null,
        parentId: null,
        leaderName: null,
        personnelName: null,
        createTime: null,
        updateTime: null,
        status: 0,
        customerUrl: null,
        applyTip: null,
        applyPersonTip: null,
        applyCompanyTip: null,
        applyGroupTip: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    //颜色修改
    selectChange(value){
      console.info(value);
      this.form.color=value;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加微信小程序配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWxconfig(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改微信小程序配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWxconfig(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWxconfig(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除微信小程序配置编号为"' + ids + '"的数据项？').then(function() {
        return delWxconfig(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('allocation/wxconfig/export', {
        ...this.queryParams
      }, `wxconfig_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.contentDiv{
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;

}
.el-color-picker--small .el-color-picker__trigger{
  height: 32px;
  width: 203px;
  margin-right: 20px;
}
.el-color-picker__trigger {
    display: inline-block;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    height: 32px;
    width: 32px;
    padding: 4px;
    border: 1px solid #e6e6e6;
    border-radius: 4px;
    font-size: 0;
    position: relative;
    cursor: pointer;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
  }
  .el-color-picker--medium .el-color-picker__trigger{
    width: 545px;
    height: 36px;
  }
.divList{
  height: 750px;
}
.scrollbar_wrap{
  height: 100%;
  overflow: hidden;
}
</style>
